package com.lvshi0797.cms.dao;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.lvshi0797.cms.entities.FProjectInfo;

@Repository("projectInfoDao")
public class ProjectInfoDao extends BaseDao<FProjectInfo> implements IProjectInfoDao {

	@SuppressWarnings("unchecked")
	@Override
	public Set<FProjectInfo> findProjectInfoBybaseId(int baseId,String niandu) {
		String sql = "select * from f_project where baseid="+baseId +" and addYear = "+niandu;
		SQLQuery query = this.getSession().createSQLQuery(sql);
		return new HashSet<FProjectInfo>(query.list());
	}

	@Override
	public void clearProjectsByBaseId(int baseId,String niandu) {
		String sql = "delete from f_project where baseid="+baseId +" and addYear = "+niandu;
		this.excuteBySql(sql);
	}

	@Override
	public void updateProject(Set<Integer> ids, int baseId) {
		for(Integer id:ids){
			String sql = "UPDATE f_project SET baseid="+baseId+" WHERE id="+id;
			this.excuteBySql(sql);
		}
	}

	@Override
	public List<FProjectInfo> listProjectInfoBybaseId(int baseId, String niandu) {
		String sql = "select id,addYear,debtMoney,item,money,peojectName,baseid from f_project where baseid="+baseId +" and addYear = "+niandu;
		SQLQuery query = this.getSession().createSQLQuery(sql);
		return query.list();
	}

}
